package com.genersoft.iot.vmp.storager.dao;

import com.genersoft.iot.vmp.storager.dao.dto.RecordInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface RecordInfoDao {

    @Insert("INSERT INTO record_info (id,app, stream, media_server_id, create_time, type, device_id, channel_id, name) VALUES" +
            "(seq_record_info.nextval,'${app}', '${stream}', '${mediaServerId}', datetime('now','localtime')), '${type}', '${deviceId}', '${channelId}', '${name}'")
    int add(RecordInfo recordInfo);

    @Delete("DELETE FROM users WHERE create_time < '${beforeTime}'")
    int deleteBefore(String beforeTime);

    @Select("select * FROM record_info")
    @Results(id="recordInfo",
    value = { 
       @Result(property = "id", column = "id"), 
       @Result(property = "app", column = "app"), 
       @Result(property = "stream", column = "stream"),
       @Result(property = "mediaServerId", column = "media_server_id"),
       @Result(property = "createTime", column = "create_time"), 
       @Result(property = "type", column = "type"), 
       @Result(property = "name", column = "name"), 
       @Result(property = "deviceId", column = "device_id"),
       @Result(property = "channelId", column = "channel_id"), 
       })
    List<RecordInfo> selectAll();
}
